package com.teemor.blog.controller;

import com.teemor.blog.api.ITopicApiService;
import com.teemor.blog.bean.condition.TbTopicCondition;
import com.teemor.blog.bean.dto.output.topic.QryTopicsODTo;
import com.teemor.blog.bean.entity.TbTopic;
import com.teemor.blog.bean.dto.input.topic.AddTopicIDTo;
import com.teemor.blog.bean.dto.input.topic.QryTopicsIDTo;
import com.teemor.blog.bean.dto.input.topic.UpdTopicIDTo;
import com.teemor.blog.bean.dto.output.topic.QryTopicODTo;
import com.teemor.blog.service.ITopicService;
import java.util.List;

import com.teemor.common.bean.utils.BeanConvertor;
import com.teemor.common.bean.utils.tmpl.BaseController;
import com.teemor.common.bean.utils.tmpl.ResponseBen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhoulk
 * @Description: 原子服务API接口实现
 * @date: 2019/11/26 14:50:14
 */
@RestController
public class TopicController extends BaseController implements ITopicApiService {
    @Autowired
    private ITopicService iTopicService;

    @Override
    public QryTopicODTo qryTopic(@PathVariable Integer topicId) {
        return BeanConvertor.convertBean(iTopicService.qryTopicById(topicId), QryTopicODTo.class);
    }

    @Override
    public int countTopic(@RequestBody QryTopicsIDTo inParam) {
        TbTopicCondition condition = BeanConvertor.convertBean(inParam, TbTopicCondition.class);
        return iTopicService.countTopic(condition);
    }

    @Override
    public ResponseBen<List<QryTopicsODTo>> qryTopicTree(QryTopicsIDTo inParam) {
        TbTopicCondition condition = BeanConvertor.convertBean(inParam, TbTopicCondition.class);
        List<QryTopicsODTo> topicsOPos = BeanConvertor.convertBeanList(iTopicService.qryTopicTree(condition), QryTopicsODTo.class);
        return returnSuccess(topicsOPos);
    }

    @Override
    public void updTopic(@RequestBody UpdTopicIDTo inParam) {
        TbTopic tbTopic = BeanConvertor.convertBean(inParam, TbTopic.class);
        iTopicService.updTopicById(tbTopic);
    }

    @Override
    public String addTopic(@RequestBody AddTopicIDTo inParam) {
        TbTopic tbTopic = BeanConvertor.convertBean(inParam, TbTopic.class);
        Integer topicId = iTopicService.addTopic(tbTopic);
        return returnData(topicId);
    }

    @Override
    public String delTopic(@RequestParam Integer topicId) {
        return returnData(iTopicService.delTopic(topicId));
    }
}